package com.adong.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Callable创建线程
 */
public class CallableDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        /*FutureTask<Integer> ft = new FutureTask<>(new MyThread02());

        new Thread(ft, "AA").start();
        new Thread(ft, "BB").start();
        System.out.println(ft.get());*/


        // lambda 表达式
        FutureTask<Integer> futureTask = new FutureTask<Integer>(() -> {
            return 200;
        });

        new Thread(futureTask, "CC").start();
        while (!futureTask.isDone()) {
            System.out.println("wait");
        }
        System.out.println(futureTask.get());
    }

}


class MyThread01 implements Runnable {

    @Override
    public void run() {

    }
}

class MyThread02 implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        System.out.println("MyThread02 call");
        return 200;
    }
}